<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>redis | 自由·生活</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link rel="icon" href="images/favicon.ico">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/MouseClickEffect.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
    <meta name="description" content="脱离生存而生活，寻求自由">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <link rel="preload" href="/assets/css/0.styles.8c3033ea.css" as="style"><link rel="preload" href="/assets/js/app.0e76bb72.js" as="script"><link rel="preload" href="/assets/js/3.c5829877.js" as="script"><link rel="preload" href="/assets/js/1.695f3f80.js" as="script"><link rel="preload" href="/assets/js/234.0e0da6a5.js" as="script"><link rel="prefetch" href="/assets/js/10.fdc11bc7.js"><link rel="prefetch" href="/assets/js/100.3e29fa54.js"><link rel="prefetch" href="/assets/js/101.19f861f4.js"><link rel="prefetch" href="/assets/js/102.0eb344c2.js"><link rel="prefetch" href="/assets/js/103.167b5aab.js"><link rel="prefetch" href="/assets/js/104.3463b648.js"><link rel="prefetch" href="/assets/js/105.fc782f3d.js"><link rel="prefetch" href="/assets/js/106.b2d60f6a.js"><link rel="prefetch" href="/assets/js/107.91f5548b.js"><link rel="prefetch" href="/assets/js/108.8bcbfcd7.js"><link rel="prefetch" href="/assets/js/109.a0dd87a3.js"><link rel="prefetch" href="/assets/js/11.5d72653a.js"><link rel="prefetch" href="/assets/js/110.8d3b5064.js"><link rel="prefetch" href="/assets/js/111.6e109181.js"><link rel="prefetch" href="/assets/js/112.7130a6e7.js"><link rel="prefetch" href="/assets/js/113.6c962a0e.js"><link rel="prefetch" href="/assets/js/114.82175aae.js"><link rel="prefetch" href="/assets/js/115.a83e6a2d.js"><link rel="prefetch" href="/assets/js/116.70ebc8b4.js"><link rel="prefetch" href="/assets/js/117.368509d0.js"><link rel="prefetch" href="/assets/js/118.54fdc470.js"><link rel="prefetch" href="/assets/js/119.64d2a2a3.js"><link rel="prefetch" href="/assets/js/12.bfde6b78.js"><link rel="prefetch" href="/assets/js/120.5b47488f.js"><link rel="prefetch" href="/assets/js/121.82865d4b.js"><link rel="prefetch" href="/assets/js/122.619e60ca.js"><link rel="prefetch" href="/assets/js/123.66c3fb26.js"><link rel="prefetch" href="/assets/js/124.4381768b.js"><link rel="prefetch" href="/assets/js/125.2f39619b.js"><link rel="prefetch" href="/assets/js/126.0c622bc6.js"><link rel="prefetch" href="/assets/js/127.caee15ee.js"><link rel="prefetch" href="/assets/js/128.99714900.js"><link rel="prefetch" href="/assets/js/129.ff59083b.js"><link rel="prefetch" href="/assets/js/13.2b3528b1.js"><link rel="prefetch" href="/assets/js/130.76df0e89.js"><link rel="prefetch" href="/assets/js/131.2333a328.js"><link rel="prefetch" href="/assets/js/132.65cff4f4.js"><link rel="prefetch" href="/assets/js/133.2c0991bc.js"><link rel="prefetch" href="/assets/js/134.fe5fc3a5.js"><link rel="prefetch" href="/assets/js/135.aef0a809.js"><link rel="prefetch" href="/assets/js/136.90fd1b1d.js"><link rel="prefetch" href="/assets/js/137.07750a3f.js"><link rel="prefetch" href="/assets/js/138.723bd2c0.js"><link rel="prefetch" href="/assets/js/139.d22450b7.js"><link rel="prefetch" href="/assets/js/14.b769124c.js"><link rel="prefetch" href="/assets/js/140.1659de26.js"><link rel="prefetch" href="/assets/js/141.f713c5ec.js"><link rel="prefetch" href="/assets/js/142.63ebd83f.js"><link rel="prefetch" href="/assets/js/143.404a833f.js"><link rel="prefetch" href="/assets/js/144.3e0107ef.js"><link rel="prefetch" href="/assets/js/145.cef80531.js"><link rel="prefetch" href="/assets/js/146.c68d17d7.js"><link rel="prefetch" href="/assets/js/147.0af3acbb.js"><link rel="prefetch" href="/assets/js/148.9f0d2452.js"><link rel="prefetch" href="/assets/js/149.28785960.js"><link rel="prefetch" href="/assets/js/15.7c3421d9.js"><link rel="prefetch" href="/assets/js/150.bf310c33.js"><link rel="prefetch" href="/assets/js/151.de6313cc.js"><link rel="prefetch" href="/assets/js/152.91a567b5.js"><link rel="prefetch" href="/assets/js/153.cfe26382.js"><link rel="prefetch" href="/assets/js/154.047349d0.js"><link rel="prefetch" href="/assets/js/155.6923503c.js"><link rel="prefetch" href="/assets/js/156.2443e22f.js"><link rel="prefetch" href="/assets/js/157.fac2fc32.js"><link rel="prefetch" href="/assets/js/158.3d470963.js"><link rel="prefetch" href="/assets/js/159.9512719e.js"><link rel="prefetch" href="/assets/js/16.baa49355.js"><link rel="prefetch" href="/assets/js/160.1a610cc3.js"><link rel="prefetch" href="/assets/js/161.b240977c.js"><link rel="prefetch" href="/assets/js/162.cfb78d5a.js"><link rel="prefetch" href="/assets/js/163.3c935aea.js"><link rel="prefetch" href="/assets/js/164.0188664b.js"><link rel="prefetch" href="/assets/js/165.6f4ba8e0.js"><link rel="prefetch" href="/assets/js/166.32b92de7.js"><link rel="prefetch" href="/assets/js/167.1087cc58.js"><link rel="prefetch" href="/assets/js/168.7e81ac69.js"><link rel="prefetch" href="/assets/js/169.5270c30b.js"><link rel="prefetch" href="/assets/js/17.2270e174.js"><link rel="prefetch" href="/assets/js/170.1d6bc941.js"><link rel="prefetch" href="/assets/js/171.e3781bc6.js"><link rel="prefetch" href="/assets/js/172.54d7bc4b.js"><link rel="prefetch" href="/assets/js/173.a88f9e1f.js"><link rel="prefetch" href="/assets/js/174.7d882351.js"><link rel="prefetch" href="/assets/js/175.7a0c6feb.js"><link rel="prefetch" href="/assets/js/176.12b22e86.js"><link rel="prefetch" href="/assets/js/177.b2230eac.js"><link rel="prefetch" href="/assets/js/178.023ba5be.js"><link rel="prefetch" href="/assets/js/179.53fa03a8.js"><link rel="prefetch" href="/assets/js/18.988151ff.js"><link rel="prefetch" href="/assets/js/180.f17c3614.js"><link rel="prefetch" href="/assets/js/181.8872481a.js"><link rel="prefetch" href="/assets/js/182.c57e38bc.js"><link rel="prefetch" href="/assets/js/183.7085d12e.js"><link rel="prefetch" href="/assets/js/184.aa164e5b.js"><link rel="prefetch" href="/assets/js/185.b7ed0f6b.js"><link rel="prefetch" href="/assets/js/186.f08304c9.js"><link rel="prefetch" href="/assets/js/187.4a10e63d.js"><link rel="prefetch" href="/assets/js/188.f0463437.js"><link rel="prefetch" href="/assets/js/189.cff969e0.js"><link rel="prefetch" href="/assets/js/19.c196a261.js"><link rel="prefetch" href="/assets/js/190.adc3524b.js"><link rel="prefetch" href="/assets/js/191.a14895a8.js"><link rel="prefetch" href="/assets/js/192.e595f819.js"><link rel="prefetch" href="/assets/js/193.3cbcef2c.js"><link rel="prefetch" href="/assets/js/194.55530a96.js"><link rel="prefetch" href="/assets/js/195.1a834f79.js"><link rel="prefetch" href="/assets/js/196.001dd10b.js"><link rel="prefetch" href="/assets/js/197.4b9de142.js"><link rel="prefetch" href="/assets/js/198.955a06ea.js"><link rel="prefetch" href="/assets/js/199.9d63eea7.js"><link rel="prefetch" href="/assets/js/20.74b35545.js"><link rel="prefetch" href="/assets/js/200.8fe0777d.js"><link rel="prefetch" href="/assets/js/201.a91425c3.js"><link rel="prefetch" href="/assets/js/202.5b89464a.js"><link rel="prefetch" href="/assets/js/203.e48d18e2.js"><link rel="prefetch" href="/assets/js/204.6cbc5c79.js"><link rel="prefetch" href="/assets/js/205.d26879e9.js"><link rel="prefetch" href="/assets/js/206.fd8688f3.js"><link rel="prefetch" href="/assets/js/207.ef25eb3d.js"><link rel="prefetch" href="/assets/js/208.9f0e5ab2.js"><link rel="prefetch" href="/assets/js/209.cbd7c763.js"><link rel="prefetch" href="/assets/js/21.3cbc9110.js"><link rel="prefetch" href="/assets/js/210.6b733c20.js"><link rel="prefetch" href="/assets/js/211.2b986a0a.js"><link rel="prefetch" href="/assets/js/212.faee0dc6.js"><link rel="prefetch" href="/assets/js/213.7ed75653.js"><link rel="prefetch" href="/assets/js/214.825d2d93.js"><link rel="prefetch" href="/assets/js/215.251aa760.js"><link rel="prefetch" href="/assets/js/216.11962b03.js"><link rel="prefetch" href="/assets/js/217.62e3335a.js"><link rel="prefetch" href="/assets/js/218.a7c3b793.js"><link rel="prefetch" href="/assets/js/219.5ff63a4c.js"><link rel="prefetch" href="/assets/js/22.d2507cce.js"><link rel="prefetch" href="/assets/js/220.28ea20d6.js"><link rel="prefetch" href="/assets/js/221.6108e4e1.js"><link rel="prefetch" href="/assets/js/222.73443d85.js"><link rel="prefetch" href="/assets/js/223.e115734d.js"><link rel="prefetch" href="/assets/js/224.499e0bab.js"><link rel="prefetch" href="/assets/js/225.70887ebb.js"><link rel="prefetch" href="/assets/js/226.e683c623.js"><link rel="prefetch" href="/assets/js/227.06f8bc32.js"><link rel="prefetch" href="/assets/js/228.82faf31a.js"><link rel="prefetch" href="/assets/js/229.0f8a6911.js"><link rel="prefetch" href="/assets/js/23.8da30b89.js"><link rel="prefetch" href="/assets/js/230.f895ca67.js"><link rel="prefetch" href="/assets/js/231.34717d1d.js"><link rel="prefetch" href="/assets/js/232.c7857239.js"><link rel="prefetch" href="/assets/js/233.6b7bcffd.js"><link rel="prefetch" href="/assets/js/235.5bc065c0.js"><link rel="prefetch" href="/assets/js/236.3e91ceb0.js"><link rel="prefetch" href="/assets/js/237.9116740e.js"><link rel="prefetch" href="/assets/js/238.8c792409.js"><link rel="prefetch" href="/assets/js/239.b4d8dfb8.js"><link rel="prefetch" href="/assets/js/24.3014a3d4.js"><link rel="prefetch" href="/assets/js/240.a1e61d58.js"><link rel="prefetch" href="/assets/js/241.3c016709.js"><link rel="prefetch" href="/assets/js/242.f8620e3f.js"><link rel="prefetch" href="/assets/js/243.8f53f134.js"><link rel="prefetch" href="/assets/js/244.424903c4.js"><link rel="prefetch" href="/assets/js/245.96c86aae.js"><link rel="prefetch" href="/assets/js/25.03ca3aa9.js"><link rel="prefetch" href="/assets/js/26.4916e6b8.js"><link rel="prefetch" href="/assets/js/27.f9aab712.js"><link rel="prefetch" href="/assets/js/28.1dfbff97.js"><link rel="prefetch" href="/assets/js/29.f7a69544.js"><link rel="prefetch" href="/assets/js/30.e3062801.js"><link rel="prefetch" href="/assets/js/31.a510760d.js"><link rel="prefetch" href="/assets/js/32.7d281288.js"><link rel="prefetch" href="/assets/js/33.6ee8ebed.js"><link rel="prefetch" href="/assets/js/34.b32e8d79.js"><link rel="prefetch" href="/assets/js/35.59d10d28.js"><link rel="prefetch" href="/assets/js/36.e1bcc1a4.js"><link rel="prefetch" href="/assets/js/37.f6c202dd.js"><link rel="prefetch" href="/assets/js/38.f8d5161a.js"><link rel="prefetch" href="/assets/js/39.1b4b64a0.js"><link rel="prefetch" href="/assets/js/4.77ea1544.js"><link rel="prefetch" href="/assets/js/40.efb0ab3f.js"><link rel="prefetch" href="/assets/js/41.85c7d269.js"><link rel="prefetch" href="/assets/js/42.36b0df70.js"><link rel="prefetch" href="/assets/js/43.c3cc85ee.js"><link rel="prefetch" href="/assets/js/44.b1575b98.js"><link rel="prefetch" href="/assets/js/45.8de97fe3.js"><link rel="prefetch" href="/assets/js/46.1fe43d4f.js"><link rel="prefetch" href="/assets/js/47.70a2e6cc.js"><link rel="prefetch" href="/assets/js/48.bb81e90c.js"><link rel="prefetch" href="/assets/js/49.8f4841fa.js"><link rel="prefetch" href="/assets/js/5.b3344219.js"><link rel="prefetch" href="/assets/js/50.e7216bda.js"><link rel="prefetch" href="/assets/js/51.1a2faa73.js"><link rel="prefetch" href="/assets/js/52.f625df74.js"><link rel="prefetch" href="/assets/js/53.b0067c47.js"><link rel="prefetch" href="/assets/js/54.0c85623e.js"><link rel="prefetch" href="/assets/js/55.491eeca5.js"><link rel="prefetch" href="/assets/js/56.8c9ffe2c.js"><link rel="prefetch" href="/assets/js/57.51902d8c.js"><link rel="prefetch" href="/assets/js/58.6d40a504.js"><link rel="prefetch" href="/assets/js/59.dbb8914b.js"><link rel="prefetch" href="/assets/js/6.a7455cf0.js"><link rel="prefetch" href="/assets/js/60.99f5caf1.js"><link rel="prefetch" href="/assets/js/61.ad9ebd9b.js"><link rel="prefetch" href="/assets/js/62.8c2c2783.js"><link rel="prefetch" href="/assets/js/63.2334b133.js"><link rel="prefetch" href="/assets/js/64.c79651bc.js"><link rel="prefetch" href="/assets/js/65.791edb2c.js"><link rel="prefetch" href="/assets/js/66.bd09db30.js"><link rel="prefetch" href="/assets/js/67.1311433b.js"><link rel="prefetch" href="/assets/js/68.8be881a0.js"><link rel="prefetch" href="/assets/js/69.f9bb1936.js"><link rel="prefetch" href="/assets/js/7.274fc010.js"><link rel="prefetch" href="/assets/js/70.77e0e02e.js"><link rel="prefetch" href="/assets/js/71.da2cc493.js"><link rel="prefetch" href="/assets/js/72.f4a80206.js"><link rel="prefetch" href="/assets/js/73.8d4c37c8.js"><link rel="prefetch" href="/assets/js/74.7a7304d5.js"><link rel="prefetch" href="/assets/js/75.2e6d01bf.js"><link rel="prefetch" href="/assets/js/76.7de509a7.js"><link rel="prefetch" href="/assets/js/77.e5e58459.js"><link rel="prefetch" href="/assets/js/78.1590a03f.js"><link rel="prefetch" href="/assets/js/79.a96442ae.js"><link rel="prefetch" href="/assets/js/8.26184cc0.js"><link rel="prefetch" href="/assets/js/80.76d4faa5.js"><link rel="prefetch" href="/assets/js/81.c79d5483.js"><link rel="prefetch" href="/assets/js/82.47926428.js"><link rel="prefetch" href="/assets/js/83.ec12a53e.js"><link rel="prefetch" href="/assets/js/84.72120681.js"><link rel="prefetch" href="/assets/js/85.30643e8b.js"><link rel="prefetch" href="/assets/js/86.64375c3f.js"><link rel="prefetch" href="/assets/js/87.7a86109f.js"><link rel="prefetch" href="/assets/js/88.68858482.js"><link rel="prefetch" href="/assets/js/89.00d57e24.js"><link rel="prefetch" href="/assets/js/9.56db4e9b.js"><link rel="prefetch" href="/assets/js/90.b7f9de16.js"><link rel="prefetch" href="/assets/js/91.e9a8e6fb.js"><link rel="prefetch" href="/assets/js/92.0b986faf.js"><link rel="prefetch" href="/assets/js/93.7c26025a.js"><link rel="prefetch" href="/assets/js/94.c39f793d.js"><link rel="prefetch" href="/assets/js/95.b74865a0.js"><link rel="prefetch" href="/assets/js/96.62558dca.js"><link rel="prefetch" href="/assets/js/97.945f9035.js"><link rel="prefetch" href="/assets/js/98.be789959.js"><link rel="prefetch" href="/assets/js/99.1adf100e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8c3033ea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-cd01cc30><div data-v-cd01cc30><div id="loader-wrapper" class="loading-wrapper" data-v-4cd7a24a data-v-cd01cc30 data-v-cd01cc30><div class="loader-main" data-v-4cd7a24a><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-623c7d26 data-v-cd01cc30 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>自由·生活</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div class="hide" data-v-cd01cc30><header class="navbar" data-v-cd01cc30><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/avatar.jpg" alt="自由·生活" class="logo"> <span class="site-name">自由·生活</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-cd01cc30></div> <aside class="sidebar" data-v-cd01cc30><div class="personal-info-wrapper" data-v-2a0ed2ae data-v-cd01cc30><img src="/images/avatar.jpg" alt="author-avatar" class="personal-img" data-v-2a0ed2ae> <h3 class="name" data-v-2a0ed2ae>
    丶忆yu'man
  </h3> <div class="num" data-v-2a0ed2ae><div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>217</h3> <h6 data-v-2a0ed2ae>文章</h6></div> <div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>15</h3> <h6 data-v-2a0ed2ae>标签</h6></div></div> <hr data-v-2a0ed2ae></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/" aria-current="page" class="sidebar-link">码农生涯</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>码农生涯</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blogs/码农生涯/interview/java-interview-questions.html" class="sidebar-link">Java面试题</a></li><li><a href="/blogs/码农生涯/interview/算法.html" class="sidebar-link">算法</a></li><li><a href="/blogs/码农生涯/interview/Java基础.html" class="sidebar-link">Java基础</a></li><li><a href="/blogs/码农生涯/interview/计算机网络.html" class="sidebar-link">计算机网络</a></li><li><a href="/blogs/码农生涯/interview/数据库.html" class="sidebar-link">数据库</a></li><li><a href="/blogs/码农生涯/interview/JVM虚拟机.html" class="sidebar-link">JVM虚拟机</a></li><li><a href="/blogs/码农生涯/interview/多线程.html" class="sidebar-link">多线程</a></li><li><a href="/blogs/码农生涯/interview/操作系统.html" class="sidebar-link">操作系统</a></li><li><a href="/blogs/码农生涯/interview/redis.html" class="active sidebar-link">redis</a></li><li><a href="/blogs/码农生涯/interview/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/blogs/码农生涯/interview/Linux.html" class="sidebar-link">Linux</a></li><li><a href="/blogs/码农生涯/interview/设计模式.html" class="sidebar-link">设计模式</a></li><li><a href="/blogs/码农生涯/interview/开放问题.html" class="sidebar-link">开放问题</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-623c7d26 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>redis</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div data-v-cd01cc30><main class="page"><div class="page-title" style="display:none;"><h1 class="title">redis</h1> <div data-v-8bc6ae5c><i class="iconfont reco-account" data-v-8bc6ae5c><span data-v-8bc6ae5c>丶忆yu'man</span></i> <i class="iconfont reco-date" data-v-8bc6ae5c><span data-v-8bc6ae5c>2021-03-31</span></i> <i class="iconfont reco-eye" data-v-8bc6ae5c><span id="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/interview/redis.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-8bc6ae5c><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-8bc6ae5c><span class="tag-item" data-v-8bc6ae5c>面试</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><div class="custom-block tip"><p>Java好难，面试让我明白了</p></div> <h1 id="redis">Redis</h1> <h2 id="简述redis">简述Redis</h2> <p>Redis是一个C语言编写的，基于内存的可持久化的key-value缓存数据库，有多种数据类型，包括字符串、列表、集合、有序集合、哈希。Redis的优点有查询快、性能更高、并且可持久化，丰富的数据类型，可备份。</p> <ol><li>redis为什么快</li> <li>redis单线程模型</li></ol> <h2 id="redis设计">Redis设计</h2> <h3 id="redis为什么快">Redis为什么快</h3> <ul><li>首先redis是基于内存的，因此查询效率高，无需跟磁盘进行交互查询数据。</li> <li>其次redis有自己设计的数据结构，并且根据这些特定的数据结构来加快查询速率，例如SDS的结构设计、跳跃表的查询等</li> <li>然后还有redis是单线程的，单线程最主要的优点就是无需线程之间进行切换，另外也不需要对资源进行上锁，一切操作都是线程安全的。</li> <li>另外最重要的就是redis中使用的是多路IO复用技术，是非阻塞的IO模型。利用select、poll、epoll来监听IO流的处理，当IO流准备好后，就去进行处理，因此单线程的情况下也能够处理多个请求。</li></ul> <h3 id="redis和memcached比较">Redis和Memcached比较</h3> <h3 id="redis单线程模型">Redis单线程模型</h3> <p>redis中是以单线程的形式存在的，而单线程又主要靠文件事件处理器来对请求监听并进行处理的。文件事件处理器主要包括五个结构，首先是有多个客户端socket请求，然后redis中使用了多路IO复用技术，因此有一个多路IO复用程序，用来监听这多个Socket请求，当其中的socket请求准备好后，就由文件事件分派器将socket关联到对应的文件事件处理器，由特定的文件事件处理器来处理这个请求并响应。</p> <h3 id="redis为什么是单线程">Redis为什么是单线程</h3> <ul><li>redis官方认为单线程已经能够满足需求，CPU并不会成为redis使用的瓶颈</li> <li>另外使用单线程结构更加简单，可维护性高，虽然在多线程的情况下能够处理更多的请求，增强处理能力，但也为程序带来了执行的不确定性，多线程的情况下需要进行线程的切换，资源的竞争、死锁等问题</li> <li>redis使用了多路IO复用技术，处理能力非常强，已经不需要多线程来增加程序的复杂性，另外单线程的情况下，许多操作，例如渐进性hash情况下直接就是线程安全的。</li></ul> <h2 id="redis数据结构">Redis数据结构</h2> <h3 id="八大数据结构">八大数据结构</h3> <ul><li>简单动态字符串（SDS）</li> <li>链表</li> <li>整数集合</li> <li>压缩链表</li> <li>字典</li> <li>跳跃表</li> <li>地图类型</li> <li>hyperloglog，记录网站UV</li> <li>位图类型</li></ul> <h3 id="五大数据类型">五大数据类型</h3> <ul><li>字符串</li> <li>列表</li> <li>集合</li> <li>整数集合</li> <li>哈希</li></ul> <h3 id="sds和c语言的比较">SDS和C语言的比较</h3> <ol><li><p>SDS的结构</p> <p>SDS的结构中有一个len变量，表示这个字符串的长度，另外这个长度也是判断字符串是否读完的依据。</p> <p>另外还有一个free变量，这个表示字符数组中还有多少的空闲空间</p></li> <li><p>比较</p> <ul><li><p>SDS获取字符串的长度是O(1)的复杂度</p></li> <li><p>SDS不会出现缓冲区溢出，也就是会先判断长度再修改，而不是先修改再判断再扩容</p></li> <li><p>修改n次字符串最多只会出现n次的内存重分配，而C语言一定会出现n次的内存重分配</p> <p>这里主要是因为SDS中的free变量，当SDS发生扩容过程时，会直接扩容到当前字符串长度len的两倍，然后进行字符串修改，多余的长度放入到free变量中，这样下次修改时可能就不需要扩容，减少内存重分配次数。</p> <p>另外当SDS长度缩短时，并不会释放SDS多余的内存空间，而是放入free变量中管理，方便下次扩容。</p></li> <li><p>SDS能够存储文本类型和二进制数</p> <p>主要因为C语言是通过空字符作为字符串的结束条件，而SDS是通过len变量进行判断</p></li> <li><p>SDS能够使用部分的C语言库函数，因为本身redis就是由C语言进行编写的。</p></li></ul></li></ol> <h3 id="redis-字典rehash和哈希表rehash的比较">redis 字典rehash和哈希表rehash的比较</h3> <p>redis哈希表的扩容采用的是渐进式hash，渐进式hash就是rehash过程并不直接完全复制整个Entry数组，而是复制一部分数据，然后整个扩容过程时分多次、渐进式的完成的。</p> <p>redis作为缓存数据库，经常要存储体量非常大的key-value数据，因此rehash的过程也是非常缓慢的，而redis采用的是单线程模型，因此扩容过程肯定会造成到用户请求的阻塞，因此使用的是渐进式rehash。在渐进式rehash过程中，复制一部分内容到新哈希表，当进行查询和更新操作时有可能会对两个哈希表进行操作，当进行查询请求时，先到第一个hash表上进行查询，没有就到新的hash表查询，当进行新增操作时，必须在新的hash表进行新增操作。</p> <h3 id="压缩链表的实现">压缩链表的实现</h3> <h3 id="简述跳跃表">简述跳跃表</h3> <p>跳跃表实际上就是一个带多层索引的有序链表，表头负责维护结点的索引指针，表尾全为null，然后链表结点的最底层存储数据，上面的层就是索引，从上到下，索引指向的结点范围逐渐缩小。当在跳跃表中进行查询时，会直接从最上层索引出发，比较值，大于就往后插，小于降低层次到下层索引继续查。跳跃表的查询时间复杂度为log(n)。</p> <h3 id="跳跃表、b树、哈希表的比较">跳跃表、B树、哈希表的比较</h3> <ul><li>哈希表在等值查询的时间复杂为O(1)，而跳跃表和B树查询的时间复杂度都是O(logn)。</li> <li>哈希表不支持范围查询，因为哈希表对键求hash映射后并不能保证有序的，而跳跃表和B树都是有序的，能够支持范围查询，但是B树范围查询时还需要进行一次中序遍历，而跳跃表可以直接定位到最小范围后往后查找。</li> <li>B树进行插入、删除操作时需要进行树的旋转，耗费时间，而跳跃表直接就可以通过断链、链接的方式来实现。</li></ul> <h2 id="持久化">持久化</h2> <p>redis持久化有两种方式，一种是RDB，一种是AOF，这两种分别对应类似于数据库的冷备份和热备份。</p> <h3 id="rdb">RDB</h3> <p>RDB持久化其实就是快照，对redis进行备份，将redis数据库中的数据以二进制的方式存储在磁盘中，并在下次启动时使用子进程来进行持久化，父进程可以继续执行自己的业务请求。</p> <h3 id="aof">AOF</h3> <p>AOF主要通过AOF日志来进行持久化，AOF日志中记录着redis数据库中使数据发生更新的操作指令。AOF日志类似于mysql中的binlog文件，当持续更新时，AOF日志文件的大小会不断变大。</p> <h3 id="混合持久化">混合持久化</h3> <p>因为RDB持久化方式记录了太多冗余数据，进行持久化时需要较长时间，另外AOF日志文件也会不断增大，并且安全性较低，因此综合两种方式来进行持久化。每过一段时间就进行RDB持久化，来保证数据的安全性，然后在两次RDB持久化的间隔中就采用AOF持久化的方式来减少重复数据。</p> <h2 id="复制">复制</h2> <h3 id="完全重同步">完全重同步</h3> <p>在从服务器初次连接，也就是进行初次复制数据时采用完全重同步，首先主服务器将RDB文件发送给从服务器，并将这个过程中缓冲区中的写命令发送给从服务器，然后从服务器开始同步数据。</p> <h3 id="部分重同步">部分重同步</h3> <p>在从服务器断线重连时采用部分重同步，这种情况下从服务器仅少了断线期间未更新的数据，因此当从服务器重新连接后，主服务器将缓冲区中的写命令发送给从服务器，然后进行数据同步。</p> <h2 id="哨兵sentinel">哨兵Sentinel</h2> <h3 id="简述哨兵">简述哨兵</h3> <h3 id="sentinel选举机制">Sentinel选举机制</h3> <h2 id="redis问题">Redis问题</h2> <h3 id="缓存雪崩">缓存雪崩</h3> <ol><li><p>介绍</p> <p>缓存雪崩是指在同一时间大规模的缓存过期失效了，然后大量的用户请求来查询缓存，由于查询不到，因此请求都会打到数据库上，造成数据库压力过大而崩掉。</p></li> <li><p>解决办法</p> <ul><li>给缓存随机设置过期时间，保证在同一时刻不会出现大面积的缓存失效。</li> <li>设置热点数据永不过期</li> <li>在分布式的情况下，将热点数据均匀分布在不同的缓存服务器中，也就是负载均衡。</li></ul></li></ol> <h3 id="缓存击穿">缓存击穿</h3> <ol><li><p>介绍</p> <p>缓存击穿是在同一时间大量请求来请求同一个数据，但是这同时这个数据失效了，这样每个请求的线程都回去查询数据库并设置缓存，服务器压力过大，造成宕机。</p></li> <li><p>解决办法</p> <ul><li>使用互斥锁，在缓存数据失效的时候，并不是立即去数据库中加载数据，而是先通过sentx去设置一个互斥键，然后再去数据库中加载数据到缓存中，这样保证其它的请求直接从缓存中获取数据。</li> <li>设置热点数据永不过期</li></ul></li></ol> <h3 id="缓存穿透">缓存穿透</h3> <ol><li><p>介绍</p> <p>缓存穿透是指请求的数据缓存中没有，数据库中也没有，例如用户不断请求id=-1的数据，缓存和数据库中肯定是没有的，而用户不断发送这种数据的请求，造成数据库压力过大，宕机。</p></li> <li><p>解决办法</p> <ul><li>在接口层增加校验，例如进行用户校验，将id&lt;=0的请求直接过滤掉。</li> <li>遇到这种带有攻击性的数据时，在缓存设置一个过期时间30s，值为null的缓存数据，这样对于这种数据的连续请求能够返回一个无用的结果，并且能够很快过期。</li> <li>使用布隆过滤器来判断数据是否存在缓存中，不存在直接返回null，否则从数据库中查询设置缓存。</li></ul></li></ol> <h3 id="布隆过滤器-bloomfilter">布隆过滤器（BloomFilter）</h3> <ol><li><p>介绍</p> <p>布隆过滤器是以位图的形式存在的，能够判断一个数据是不是在布隆过滤器中不存在，注意，布隆过滤器只能判断数据是否不存在于布隆过滤器中，而不能保证一定存在。</p></li> <li><p>实现方式</p> <p>布隆过滤器是一个bit或者bit向量，开始要构造布隆过滤器，缓存中的数据经过多个不同的hash函数计算哈希值，然后将对应hash值指向的bit位设置为1，如果原来bit位上已经为1就进行覆盖。因此布隆过滤器中就包括缓存数据库中所有数据的多函数映射。</p> <p>当我们要判断一个key是否不存在时，直接让这个key通过之前的多个hash函数计算hash值，如果发现有对应hash值的bit位上不为1，这就代表redis缓存中一定不存在这个key，直接返回不存在。但是如果所有的bit位上都为1的话，那也只能说这个key可能存在，因为不同key值经过hash运算后hash值可能相同。</p></li></ol> <h3 id="redis、数据库一致性问题">redis、数据库一致性问题</h3> <ul><li><p>读操作</p> <p>对于读操作，基本上是一个固定请求策略：</p> <ol><li>首先客户端请求服务器时，先去redis缓存中看数据是否存在，如果存在，直接返回缓存中的数据。</li> <li>如果缓存中的数据失效或者不存在了，就会去请求数据库，然后把从数据库中查询出来的数据设置在缓存中。</li> <li>之后就将数据返回给客户端。</li></ol></li> <li><p>写操作</p> <p>对于写操作，有三种更新策略，但是每种策略都会造成缓存和数据库的不一致问题。</p></li></ul> <ol><li><p>更新数据库也更新缓存</p> <p>这种策略是由应用层去设置并更新缓存，因此最终数据库和缓存都交由应用层进行维护。</p> <ul><li><p>先更新数据库再更新缓存</p> <p>使用这种策略在高并发的情况下会造成脏读的问题，比如两个线程A、B先后对一个数据进行更新，开始A更新数据库，然后去更新缓存，此时B也更新了数据库再去更新缓存，然后B先更新成功，这就会造成缓存被A线程的旧数据覆盖。</p></li> <li><p>先更新数据库再删除缓存（重要）</p> <p>正常情况使用更多的方法，使用这种策略在高并发的情况下也会发生脏读，两个线程一个读一个写，并且先后顺序不一致下就会使缓存数据库中的数据为旧数据。</p> <p>另外这种情况下还有一个特别的情况，就是如果删除缓存失败的话，也会造成脏读的情况，因此需要进行不一致性问题的解决。</p></li> <li><p>先删除缓存再更新数据库（这个应该不重要）</p> <p>这种情况下也会造成脏读的问题，也是两个线程一个读一个写，读线程快于写线程数据库更新，慢于写线程的缓存删除，这样也会导致缓存中仍然存有旧的数据。</p></li></ul></li> <li><p>更新缓存，缓存同步数据库</p> <p>这种策略应用层只需要去维护缓存，缓存和数据库的同步交由缓存去实现。这里主要体现的就是缓存自己去实现同步。</p> <ul><li><p>read through</p> <p>读的情况下是在查询的时候去更新缓存，查询时当缓存失效后，由缓存自己来从数据库中加载数据。</p></li> <li><p>write through</p> <p>写的情况下是当缓存命中时，直接更新缓存，然后由缓存去进行同步操作，当缓存未命中，就更新数据库。</p></li></ul></li> <li><p>更新缓存，缓存异步更新数据库</p> <p>这种策略下完全只更新缓存，不会立马更新数据库，由缓存在一定的时间后去对数据库进行更新操作。这种情况适合高并发情况下的更新操作，因为要不断的更新数据，因此直接更新缓存，再讲更新操作放在一个事务中去更新数据库，可以做到多次更新，一次保存。</p></li></ol> <h3 id="怎样实现redis高可用">怎样实现Redis高可用</h3> <ul><li>持久化机制</li> <li>主从服务器复制</li> <li>哨兵Sentinel</li> <li>集群</li></ul> <p><strong>注意：</strong> 主从服务器和集群的区别</p> <p>主从服务器中每个服务器存储着所有的缓存数据，或者说主从服务器在一定程度上是一样的。查询在从服务器，写在主服务器。</p> <p>而集群是指所有的数据通过某种方式，例如哈希映射的方法，数据分片存储在不同的节点上，然后查询是在所有的节点上进行查询。</p> <h3 id="不一致问题怎样解决">不一致问题怎样解决</h3> <ul><li>给缓存设置过期时间（一般情况下都会有）</li> <li>删除缓存失败后快速重试</li> <li>使用消息队列记录删除缓存失败的key，然后不断取出重试，失败再加入队列。</li> <li>定期的对缓存数据库中的数据进行全量更新，也就是一次清掉再加载。</li> <li>解析mysql中的binlog日志文件，使用canal等开源框架对binlog日志进行解析，然后写入到redis缓存中，也就是采用发布-订阅的模式进行同步操作。</li></ul> <h2 id="分布式锁redission">分布式锁Redission</h2> <h3 id="一致性hash">一致性Hash</h3></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021/4/11 上午12:01:19</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c8d125c6 data-v-c8d125c6><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c8d125c6><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c8d125c6></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c8d125c6></path></svg></div><APlayer audio="" fixed="true" mini="true" theme="#b7daff" loop="loop" order="random" preload="auto" volume="0.08" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/assets/js/app.0e76bb72.js" defer></script><script src="/assets/js/3.c5829877.js" defer></script><script src="/assets/js/1.695f3f80.js" defer></script><script src="/assets/js/234.0e0da6a5.js" defer></script>
  </body>
</html>
